package com.meilai.project.controller.web.business.dataLevel;


import com.meilai.project.dto.base.ApiResult;
import com.meilai.project.dto.business.dataLevel.DataLevelDTO;
import com.meilai.project.dto.business.dataLevel.DataLevelRemoveDTO;
import com.meilai.project.entity.personnel.org.Role;
import com.meilai.project.service.business.dataLevel.DataQueryBusinessLevelService;
import com.meilai.project.vo.business.dataLevel.DataLevelVO;
import com.meilai.project.vo.business.dataLevel.LevelUserVO;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 数据业务表 前端控制器
 * </p>
 *
 * @author xhy
 * @since 2022-09-21
 */
@RestController
@RequestMapping("/api/web/data/level")
public class DataQueryBusinessController {

    @Autowired
    private DataQueryBusinessLevelService dataQueryBusinessLevelService;


    @ApiModelProperty("查询所有业务,返回表格数据")
    @GetMapping("/list")
    public ApiResult<List<DataLevelVO>> list() {
        return ApiResult.ok(dataQueryBusinessLevelService.queryDataLevelVOList());
    }

    @ApiModelProperty("保存等级数据")
    @PostMapping("/add/level")
    public ApiResult<Boolean> saveLevel(@RequestBody DataLevelDTO dto) {
        return ApiResult.ok(dataQueryBusinessLevelService.saveLevel(dto));
    }

    @ApiModelProperty("添加角色数据")
    @PostMapping("/add/level/role")
    public ApiResult<Boolean> addLevelRole(@RequestBody DataLevelDTO dto) {
        return ApiResult.ok(dataQueryBusinessLevelService.addLevelRole(dto));
    }

    @ApiModelProperty("添加用户数据")
    @PostMapping("/add/level/user")
    public ApiResult<Boolean> addLevelUser(@RequestBody DataLevelDTO dto) {
        return ApiResult.ok(dataQueryBusinessLevelService.addLevelUser(dto));
    }

    @ApiModelProperty("删除等级角色数据")
    @PostMapping("/remove/level/role")
    public ApiResult<Boolean> removeLevelRole(@RequestBody DataLevelRemoveDTO dto) {
        return ApiResult.ok(dataQueryBusinessLevelService.removeLevelRole(dto));
    }

    @ApiModelProperty("删除等级用户数据")
    @PostMapping("/remove/level/user")
    public ApiResult<Boolean> removeLevelUser(@RequestBody DataLevelRemoveDTO dto) {
        return ApiResult.ok(dataQueryBusinessLevelService.removeLevelUser(dto));
    }

    @ApiModelProperty("删除等级数据")
    @PostMapping("/remove/level")
    public ApiResult<Boolean> removeLevel(@RequestParam("code") String code, @RequestParam("level") Integer level) {
        return ApiResult.ok(dataQueryBusinessLevelService.removeLevel(code, level));
    }


    @ApiModelProperty("查询可选择的角色数据")
    @GetMapping("/queryRoleByLevel")
    public ApiResult<List<Role>> queryRoleByLevel(@RequestParam("code") String code, @RequestParam("level") Integer level) {
        return ApiResult.ok(dataQueryBusinessLevelService.queryCanAddRoleList(code, level));
    }

    @ApiModelProperty("查询用户等级并分组")
    @GetMapping("/queryLevelUserVO")
    public ApiResult<List<LevelUserVO>> queryLevelUserVO(@RequestParam("code") String code) {
        return ApiResult.ok(dataQueryBusinessLevelService.queryLevelUserVO(code));
    }
}
